package com.oliver.proxy.midjourney.interfaces.controller;

import com.oliver.proxy.midjourney.application.service.TaskListService;
import com.oliver.proxy.midjourney.domain.entity.TaskList;
import com.oliver.proxy.midjourney.interfaces.dto.CreateTaskRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/tasks")
public class TaskListController {
    private final TaskListService taskListService;

    public TaskListController(TaskListService taskListService) {
        this.taskListService = taskListService;
    }

    @PostMapping
    public ResponseEntity<Long> createTask(@Valid @RequestBody CreateTaskRequest request) {
        Long taskId = taskListService.createTask(request);
        return ResponseEntity.ok(taskId);
    }

    @PutMapping("/{taskId}")
    public ResponseEntity<Void> updateTask(@PathVariable Long taskId, @RequestBody TaskList taskList) {
        taskList.setTaskId(taskId);
        taskListService.updateTask(taskList);
        return ResponseEntity.ok().build();
    }

    @DeleteMapping("/{taskId}")
    public ResponseEntity<Void> deleteTask(@PathVariable Long taskId) {
        taskListService.deleteTask(taskId);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/{taskId}")
    public ResponseEntity<TaskList> getTask(@PathVariable Long taskId) {
        TaskList task = taskListService.getTask(taskId);
        return ResponseEntity.ok(task);
    }

    @GetMapping
    public ResponseEntity<List<TaskList>> getAllTasks() {
        List<TaskList> tasks = taskListService.getAllTasks();
        return ResponseEntity.ok(tasks);
    }

    @GetMapping("/category/{category}")
    public ResponseEntity<List<TaskList>> getTasksByCategory(@PathVariable String category) {
        List<TaskList> tasks = taskListService.getTasksByCategory(category);
        return ResponseEntity.ok(tasks);
    }
} 